﻿<UserControl x:Class="MailboxPermissionsManager.Views.MailboxView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:viewModels="clr-namespace:MailboxPermissionsManager.ViewModels"
             xmlns:views="clr-namespace:MailboxPermissionsManager.Views">
    
    <DockPanel Background="White">
        <Expander DockPanel.Dock="Right" ExpandDirection="Left">
            <Expander.Header>
                <TextBlock Text="Advanced Options" Margin="0"
                           FontSize="14"
                           FontWeight="Bold">
                    <TextBlock.LayoutTransform>
                        <RotateTransform Angle="90"/>
                    </TextBlock.LayoutTransform>
                </TextBlock>
            </Expander.Header>
            <Expander.Content>
                <views:AdvancedOptionsView/>
            </Expander.Content>
        </Expander>
        <StatusBar DockPanel.Dock="Bottom">
            <StatusBarItem Content="{Binding Status}" MinHeight="22" HorizontalAlignment="Left"/>
            <StatusBarItem Content="{Binding Path=Delegates.Status}" HorizontalAlignment="Right" />
        </StatusBar>
        <Grid DockPanel.Dock="Top">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="50*" MinWidth="150"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="50*" MinWidth="150"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*" MinHeight="270"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*" MinHeight="150"/>
            </Grid.RowDefinitions>

            <TextBlock Grid.Column="0" Grid.Row="0" FontSize="14" FontWeight="Bold" Text="{Binding Mailbox.PrimarySmtp}"/>
            
            <TreeView x:Name="tree" Grid.Column="0" Grid.Row="1" Grid.RowSpan="3" ItemsSource="{Binding Folders}">
                <TreeView.ItemContainerStyle>
                    <Style TargetType="{x:Type TreeViewItem}">
                        <Style.Resources>
                            <!--SelectedItem with focus-->
                            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Blue" Opacity=".4"/>
                            <!--SelectedItem without focus-->
                            <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Blue" Opacity=".4"/>
                        </Style.Resources>
                        <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}"/>
                        <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
                    </Style>
                </TreeView.ItemContainerStyle>
                <TreeView.ItemTemplate>
                    <HierarchicalDataTemplate ItemsSource="{Binding SubfolderViewModels}" DataType="{x:Type viewModels:MailboxFolderViewModel}">
                        <TextBlock Text="{Binding FolderWrapper.Name}"
                                   Foreground="{Binding RelativeSource={RelativeSource AncestorType=TreeViewItem, Mode=FindAncestor}, Path=Foreground}"/>
                    </HierarchicalDataTemplate>
                </TreeView.ItemTemplate>
            </TreeView>
            
            <views:FolderView Grid.Column="2" Grid.Row="0" Grid.RowSpan="2" DataContext="{Binding ElementName=tree,Path=SelectedItem}"/>

            <views:DelegatesView Grid.Column="2" Grid.Row="3" DataContext="{Binding Delegates}"/>
            
            <GridSplitter Grid.Column="1" HorizontalAlignment="Center" Width="4"
                      VerticalAlignment="Stretch" Grid.RowSpan="5"/>
            
            <GridSplitter Grid.Column="2" Grid.Row="2" HorizontalAlignment="Stretch" VerticalAlignment="Center" Height="4"/>
        </Grid>
    </DockPanel>
</UserControl>
